<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>登录</title>
<link rel="stylesheet" type="text/css" href="css/index.css" />
	<script src="jquery.1.11.js"></script>
</head>

<body>

<img class="bgone" src="img/E3.jpg" />
<img class="pic" src="img/E3.png" />

<div class="table">
	<div class="wel">电子科大基线扫描平台</div>
	<div class="wel1">第四小组</div>
	<div class="user">
		<div id="yonghu" style=""><img src="img/yhm.png" /></div>
		<input type="text" id="username" placeholder="用户名" />
	</div>			
	<div class="password">
		<div id="yonghu"><img src="img/mm.png" /></div>
		<input type="password" id="password" placeholder="●●●●●●"/>
	</div>
	<input class="btn" type="button" id="loginButton" value="登录" />
</div>

</body>
<script>
	$(function () {

		$("#loginButton").click(function () {
			let username = $("#username").val();
			let password = $("#password").val();
			// ajax  异步请求行为
			$.ajax({
				url:"/user/login",           // 请求路径
				type:"post",                  // 请求的方式，不区分大小写
				cache:false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
				contentType:"application/json;charset=utf-8",   // 向服务器发送一个json对象
				data: JSON.stringify({
					username:username,
					password:password,
				}),
				datatype:"json",        // 返回类型，text文本、html页面、json数据
				success:function(response){   // response = {"code":200,"user":{"id":1,"username":"dk001","password":"668800"}}
					console.log("返回: " + response);
					alert(response.msg);
					if(response.code === 200) {
						window.location.href = "/index.html";
					}
				},
				error:function(response){
					console.log("出错返回: " + response);
				}
			});
		});
	});
</script>
</html>